#!/bin/bash

PROXYSQL_LIB_DIR="/var/lib/proxysql"
PROXYSQL_LOG_DIR="/var/log/kolla/proxysql"

if [[ ! -d "${PROXYSQL_LOG_DIR}" ]]; then
    mkdir -p "${PROXYSQL_LOG_DIR}"
fi
chown -R proxysql:kolla "${PROXYSQL_LOG_DIR}"

# Proxysql has configuration stored in
# its own internal DB and config file
# is used only for bootstrap DB by default.
# Once DB is bootstraped, config
# file is ignored.
#
# This behaviour is not what we want
# while configuring via kolla-ansible.
# Therefore let's remove internal DB
# and bootstrap it every time as config
# file is generated on kolla-ansible side.
rm -f ${PROXYSQL_LIB_DIR}/proxysql.db

# Remove old pid
rm -f ${PROXYSQL_LIB_DIR}/proxysql.pid

# As proxysql supports only one
# configuration file, there is a
# script which reads global and services
# configs (similar to haproxy) and
# generate single configuration file
# from which is internal DB created
# every time.
kolla_proxysql_config_sync
